package com.mlnx.push.config;

import com.mlnx.device.session.SessionManagerFactory;
import com.mlnx.push.websocket.server.WebsocketPushNettyServer;
import com.mlnx.push.websocket.server.session.WebsocketPushManager;
import com.mlnx.service.base.properties.MutilDeviceProperties;
import com.mlnx.service.base.properties.PushProperties;

import org.shan.mq.common.topic.SimpleTopicPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Created by amanda.shan on 2019/11/1.
 */
@Configuration
public class PushConfig {

    public static PushProperties PUSH_PROPERTIES;

    @Autowired
    private MutilDeviceProperties mutilDeviceProperties;

    @PostConstruct
    public void init() throws Exception {

        PUSH_PROPERTIES = mutilDeviceProperties.getPush();

        if (mutilDeviceProperties.getPush().isEnable()) {
            WebsocketPushManager websocketPushManager = new WebsocketPushManager();
            websocketPushManager.setTopicPolicy(new SimpleTopicPolicy());

            SessionManagerFactory.getInstance().setPushSessionManager(websocketPushManager);

            WebsocketPushNettyServer websocketPushNettyServer = new WebsocketPushNettyServer();
            websocketPushNettyServer.start(mutilDeviceProperties.getPush().getWebsocketPushPort(), false);
        }
    }
}
